package com.rolfhoward.video.record.widget

import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.PopupWindow
import com.rolfhoward.video.R

/**
 *@author wuqiubin
 *@date 2023/1/16
 *@Describe 相机预览尺寸弹窗
 */
class RatioPopupWindow(context: Context?):PopupWindow(context) {
    private var mView: View? = null
    init {
        mView = LayoutInflater.from(context).inflate(R.layout.view_video_preview_ratio, null, false)

        isClippingEnabled = false
        contentView = mView?.rootView
        width = ViewGroup.LayoutParams.WRAP_CONTENT
        height = ViewGroup.LayoutParams.WRAP_CONTENT
        isFocusable = false
        setBackgroundDrawable(ColorDrawable(0))
    }

    /**显示弹窗*/
    fun showPop(view: View?){
        if (!isShowing){
            mView?.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
            showAsDropDown(view,(-mView?.measuredWidth!! + view?.width!!)/2, 0)
        }else{
            dismiss()
        }
    }

    /**隐藏弹窗*/
    fun hindPop(){
        if (isShowing){
            dismiss()
        }
    }
}